<template>
    <div class="storeInfo">
        <div class="head">
            <el-form :model="form" class="headForm">
                
                <el-form-item label="" style="width:105px">
                <el-select v-model="form.category_id" placeholder="套餐分类">
                    <el-option label="套餐分类" value=""></el-option>
                    <el-option v-for="(item,catI) in categoryList" :key="catI" :label="item.cate_name" :value="item.category_id" ></el-option>
                </el-select>
                </el-form-item>

                <el-form-item label="" style="width:105px">
                <el-select v-model="form.has_time" placeholder="房时">
                    <el-option label="房时" value=""></el-option>
                    <el-option label="不包含房时" value="0"></el-option>
                    <el-option label="包含房时" value="1"></el-option>
                </el-select>
                </el-form-item>

                <el-form-item label="" style="width:105px">
                <el-select v-model="form.combo_kind" placeholder="适用场景">
                    <el-option label="适用场景" value=""></el-option>
                    <el-option label="通用" value="0"></el-option>
                    <el-option label="KTV包房" value="1"></el-option>
                    <el-option label="卡座酒吧" value="2"></el-option>
                </el-select>
                </el-form-item>

                <el-form-item label="" style="width:105px">
                <el-select v-model="form.combo_type" placeholder="平台属性">
                    <el-option label="平台属性" value=""></el-option>
                    <el-option label="魅KTV" value="0"></el-option>
                    <el-option label="美团团购" value="1"></el-option>
                    <el-option label="美团预订" value="2"></el-option>
                    <el-option label="口碑团购" value="3"></el-option>
                    <el-option label="口碑预订" value="4"></el-option>
                </el-select>
                </el-form-item>


                <el-form-item label="" style="width:105px">
                <el-select v-model="form.combo_cate" placeholder="套餐级别">
                    <el-option label="套餐级别" value=""></el-option>
                    <el-option label="L1" value="1"></el-option>
                    <el-option label="L2" value="2"></el-option>
                    <el-option label="L3" value="3"></el-option>
                </el-select>
                </el-form-item>




                <el-form-item label="" style="width:105px">
                <el-input v-model="form.name" placeholder="套餐名称"></el-input>
                </el-form-item>


                <el-form-item label="" style="width:105px">
                <el-input v-model="form.desc" placeholder="套餐描述"></el-input>
                </el-form-item>



                 <el-form-item label="" style="width:105px">
                <el-select v-model="form.status" placeholder="上下架">
                    <el-option label="上下架" value=""></el-option>
                    <el-option value="0" label="上架"></el-option>
                    <el-option value="1" label="下架"></el-option>
                </el-select>
                </el-form-item>

                
                <el-button type="primary" icon="el-icon-search" @click="search">搜索</el-button>
                <el-button type="danger" @click="theClick('add')">添加</el-button>


            </el-form>
            
        </div>
         
        <!-- tab部分 -->
        <div class="tabContainer" v-if="tableData !== undefined &&  tableData.length != 0">
            <el-table :data="tableData" stripe style="width: 100%;text-align:center">
                <!-- <el-table-column :prop="item.bar" :label="item.name" fixed v-for="(item,index) in tabBar" :key="index">
                    <img :src="item.bar" alt="" v-if="item.name == '封面'">
                </el-table-column> -->

                <el-table-column prop="combo_id" label="ID" fixed></el-table-column>
                <el-table-column prop="cover_image" label="封面">
                    <template   slot-scope="scope">            
                        <img :src="scope.row.combo_images[0]+'?x-oss-process=image/resize,m_fill,w_60,h_50/quality,q_50'"  min-width="60" height="50" :onerror="defunltImg"/>
                    </template>   
                </el-table-column>
                <el-table-column prop="combo_name" label="套餐名称" width="200"></el-table-column>
                <el-table-column prop="has_time_cn" label="房时套餐"></el-table-column>
                <el-table-column prop="category_name" label="分类"></el-table-column>
                <el-table-column prop="platform_cn" label="平台属性">
                    <template slot-scope="scope">
                        <p v-html='scope.row.platform_cn'></p>
                    </template>
                </el-table-column>
                <el-table-column prop="combo_desc_cn" label="套餐明细" width="200">
                    <template slot-scope="scope">
                        <div v-html='scope.row.combo_desc_cn'></div>
                    </template>
                </el-table-column>

                <!-- <el-table-column prop="grade" label="消费能力"></el-table-column> -->
                <el-table-column prop="update_time" label="更新时间"></el-table-column>
                <el-table-column prop="combo_cate_cn" label="级别" ></el-table-column>
                <el-table-column  label="操作" prop="combo_id" v-if="limitList !== undefined && limitList.length>0">
                    <template  slot-scope="scope">  
                        <div>
                            <span  class="lightFont" @click="theClick(limitList[0].url,scope.row.combo_id,scope.row.combo_status)">
                                <i>{{limitList[0].name}}&nbsp;|&nbsp;</i>
                            </span>
                            <el-tooltip placement="bottom">
                                <div slot="content">
                                    <span v-for="(item,indexLimit) in limitList" :key="indexLimit">
                                        <i v-if="indexLimit != 0">
                                           <em v-if="item.url == 'shelf' && scope.row.combo_status == 0" class="hoverBtn" @click="theClick(item.url,scope.row.combo_id,scope.row.combo_status)">下架</em> 
                                           <em v-else-if="item.url == 'shelf' && scope.row.combo_status != 0" class="hoverBtn" @click="theClick(item.url,scope.row.combo_id,scope.row.combo_status)">上架</em> 
                                           <em v-else class="hoverBtn" @click="theClick(item.url,scope.row.combo_id,scope.row.combo_status)">{{item.name}}</em> 
                                        </i>
                                    </span>
                                </div>
                                <i class="lightFont">更多</i>
                            </el-tooltip>
                        </div>          
                        
                    </template>

                </el-table-column>
                <el-table-column label="操作"  v-else>/</el-table-column>

            </el-table>
                        
        </div>
        <!-- 分页部分 -->
        <!-- 分页部分 -->
        <el-pagination
            background
            layout="total, prev, pager, next, jumper"
            @current-change="changePage"
            :page-size="size"
            :current-page.sync="pageNum"
            :hide-on-single-page=true
            :total="total">{{total}}
        </el-pagination>
        <!-- 编辑、复制、添加弹框 -->
        <el-dialog title="编辑" :visible.sync="editShow" style="width：690px">
            <el-form :model="editForm">
                <el-form-item label="套餐分类" :label-width="editW">
                    <el-radio v-for="(item,index) in categoryList" :key="index" @click="changehastime(editForm.category_id)" v-model="cateId" :label="item.category_id">{{item.cate_name}}</el-radio>
                </el-form-item>
                <el-form-item label="是否含房时"  :label-width="editW">
                    <el-radio v-model="editForm.has_time" label="1">含房时</el-radio>
                    <el-radio v-show="cateId != 31" v-model="editForm.has_time" label="0">不含房时</el-radio>
                    
                </el-form-item>
                <el-form-item v-if="editForm.has_time == 0" label="适用场景"  :label-width="editW">
                    <el-radio v-model="editForm.combo_kind" label="1">KTV包房</el-radio>
                    <el-radio v-model="editForm.combo_kind" label="2">卡座酒吧</el-radio>
                    <el-radio v-model="editForm.combo_kind" label="0">通用</el-radio>
                </el-form-item>
                <el-form-item label="套餐名称" :label-width="editW">
                    <el-input v-model="editForm.combo_name" autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item>
                    <uploadBox spantxt="套餐封面" :needWidth = 'editW' :coverImg="$store.state.comboimg" :coverPath="combo_images" v-on:throwFilePath="imgUrl"></uploadBox>
                </el-form-item>
                
                <el-form-item label="平台属性" :label-width="editW">
                    <!--0-0-0: platform-meituan_type-koubei_type -->
                    <el-checkbox-group v-model="platarr" @change="platfn">
                        <el-checkbox label="0">魅KTV</el-checkbox>
                        <div>
                            <el-checkbox label="1-1">美团团购</el-checkbox>                        
                            <el-checkbox label="1-2">美团预定</el-checkbox> 
                            <div style="display:inline-block"  v-show="meituanval == '1-1'">
                                <span>美团团购价格:</span>
                                <el-input v-model="editForm.meituan_unit_price" autocomplete="off" style="width:80px;margin-left:5px"></el-input>   
                            </div>   
                        </div>
                        
                        <div>
                            <el-checkbox label="2-1">口碑团购</el-checkbox>
                            <el-checkbox label="2-2">口碑预订</el-checkbox>  
                             <div style="display:inline-block" v-show="koubeival == '2-1'">
                                <span>口碑团购价格:</span>
                                <el-input v-model="editForm.koubei_unit_price" autocomplete="off" style="width:80px;margin-left:5px"></el-input>   
                            </div> 
                        </div>
                        
                    </el-checkbox-group>
                </el-form-item>
                <el-form-item label="有效期" :label-width="editW">
                    <el-radio v-model="editForm.property" label="0">长期有效</el-radio><br>
                    <div style="margin-bottom:5px">
                        <el-radio v-model="editForm.property" label="2">有效期至</el-radio> 
                        <el-date-picker v-model="editForm.date2" type="datetime" placeholder=""></el-date-picker>   
                    </div>
                    
                    <el-radio v-model="editForm.property" label="1">当天有效</el-radio>
                    <el-date-picker v-model="editForm.date1" type="datetime" placeholder=""></el-date-picker>
                </el-form-item>
                <el-form-item>
                    <sortgoodBox searchgoodurl="v1/item/search" txt="商品及数量" :showWidth="editW" :curgood="editForm.items_detail" v-on:throwFilePath="getsearchgoods"></sortgoodBox>
                </el-form-item>
                <el-form-item label="套餐描述" :label-width="editW">
                    <el-input class="texta" type="textarea" :rows="2" placeholder="请输入内容" v-model="editForm.combo_desc"></el-input>
                </el-form-item>
                <!-- 这里有合成图片---两个 -->
                <el-form-item label="自动合成LED" :label-width="editW">
                    <ledBox :led='$store.state.ledpath' :showled="$store.state.ledsrc" :autoLED="autoLED" v-on:ledimgs="led_data_img"></ledBox>
                </el-form-item>



                <!-- 周次 -->
                <el-form-item label="展示周次" :label-width="editW">
                    <el-checkbox-group v-model="use_days" @change="useDays">
                        <!--             -->
                        <el-checkbox v-for="(witem,index) in weekend" :key="index" :label="witem.val">{{witem.name}}</el-checkbox>
                    </el-checkbox-group>
                </el-form-item>


                <el-form-item label="展示客户端" :label-width="editW">
                    <el-checkbox-group v-model="use_plat" @change="usePlat">
                        <el-checkbox v-for="(witem,index) in platList" :key="index" :label="witem.val">{{witem.name}}</el-checkbox>
                    </el-checkbox-group>
                </el-form-item>


                <!-- 特色价格设置 -->
                <el-form-item  v-if="editForm.category_id==31" label="特色套餐" :label-width="editW">
                    <div style="display:inline-block">
                        <span>优惠价:</span>
                        <el-input v-model="tese_member_price" autocomplete="off" style="width:80px;margin-left:5px"></el-input>   
                    </div>
                    
                    <div style="display:inline-block">
                        <span>销售价:</span>
                        <el-input v-model="tese_normal_price" autocomplete="off" style="width:80px;margin-left:5px"></el-input>   
                    </div>
                </el-form-item>
                <el-form-item class="radioT_C" label="房时档位" :label-width="editW" v-if="editForm.category_id==31">
                    <el-radio @change="computeComboPrice(1)" v-model="computerSelected" label="1">大包房级以上房型黄金档3小时,阳光档6小时,午夜档周内7小时,周末6小时</el-radio>
                    <el-radio @change="computeComboPrice(2)" v-model="computerSelected" label="2">大包房及以上房型全天欢唱</el-radio><br>
                    <el-radio @change="computeComboPrice(3)" v-model="computerSelected" label="3">所有档位均3小时欢唱</el-radio>
                    <p style="font-size:12px;color:red">*默认小包房和中包房全天欢唱</p>
                </el-form-item>
                <el-form-item class="radioT_C" label="房时档位" :label-width="editW" v-if="editForm.category_id==2">
                    <el-radio @change="computeComboPrice(4)" v-model="computerSelected" label="4">仅阳光档可用,周末周内3小时</el-radio>
                    <el-radio @change="computeComboPrice(5)" v-model="computerSelected" label="5">仅阳光档可用,周末3小时周内4小时</el-radio><br>
                    <el-radio @change="computeComboPrice(6)" v-model="computerSelected" label="6">阳光档欢唱6小时,黄金档欢唱3小时,午夜档周内7小时,周末6小时</el-radio>
                    <el-radio @change="computeComboPrice(7)" v-model="computerSelected" label="7">阳光档欢唱6小时,黄金档周末3小时,周内4小时,午夜档周内7小时,周末6小时</el-radio>
                    <el-radio @change="computeComboPrice(8)" v-model="computerSelected" label="8">所有档位均3小时欢唱</el-radio>
                </el-form-item>
                <el-form-item v-if="editForm.category_id == 2" label="商品折扣系数" :label-width="editW">
                    <el-input placeholder="默认商品折扣系数为1" v-model="editForm.discount"></el-input>
                </el-form-item>
                    <table border="0" cellspacing="0" cellpadding="0" class="thepriceTab" align="center">
                         <thead style="width:100%">
                            <tr align="center" valign="middle">
                                <th style="width:70px">属性</th>
                                <th style="width:70px">包房类型</th>
                                <th style="width:70px">档位</th>
                                <th style="width:50px">房时</th>
                                <th style="width:100px">优惠价</th>
                                <th style="width:100px">销售价</th>
                                <th style="width:100px">房时价</th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr align="center" v-for="(item,c) in roomList" :key="'0'+c" valign="middle">
                                <td rowspan="5" v-if="c==0">平日</td>
                                <td >{{item.charmber_name}}</td>
                                <td>
                                    <ul class="ulBox">    

                                        <li v-for="(items,p) in item.voucher" :key="'0'+p">{{items.period_name}}</li>
                                    </ul>
                                </td>
                                <td>
                                    <!-- 房时 时长-->
                                    <ul class="ulBox">
                                        <li v-for="(items,p) in item.voucher" :key="'0'+p"><input type="text" v-model="items.time_length"></li>
                                    </ul> 
                                </td>
                                <td>
                               <!-- 优惠价 -->
                                    <ul class="ulBox longerInput">
                                        <li v-for="(items,p) in item.voucher" :key="'0'+p"><input type="text" v-model="items.member_price"></li>
                                    </ul>
                                </td>
                                <td>
                                    <!-- 销售价 -->
                                    <ul class="ulBox longerInput">
                                        <li v-for="(items,p) in item.voucher" :key="'0'+p"><input type="text" v-model="items.normal_price"></li>
                                    </ul>
                                </td>
                                <td>
                                    <!-- 房时价 -->
                                    <ul class="ulBox longerInput">
                                        <li v-for="(items,p) in item.voucher" :key="'0'+p"><input type="text" v-model="items.time_price"></li>
                                    </ul>
                                </td>
                            </tr>
                               <!--       周末                         -->
                            <tr align="center" v-for="(item,c) in roomList" :key="c" valign="middle">
                                <td rowspan="5" v-if="c==0">周末</td>
                                <td >{{item.charmber_name}}</td>
                                <td>
                                    <ul class="ulBox">
                                        <li v-for="(items,p) in item.voucher" :key="p">{{items.period_name}}</li>
                                    </ul>
                                </td>
                                <td>
                                    <!-- 房时 时长 weekend_member_price-->
                                    <ul class="ulBox">
                                        <li v-for="(items,p) in item.voucher" :key="p"><input type="text" v-model="items.weekend_time_length"></li>
                                    </ul> 
                                </td>
                                <td>
                               <!-- 优惠价 -->
                                    <ul class="ulBox longerInput">
                                        <li v-for="(items,p) in item.voucher" :key="p"><input type="text" v-model="items.weekend_member_price"></li>
                                    </ul>
                                </td>
                                <td>
                                    <!-- 销售价 -->
                                    <ul class="ulBox longerInput">
                                        <li v-for="(items,p) in item.voucher" :key="p"><input type="text" v-model="items.weekend_normal_price"></li>
                                    </ul>
                                </td>
                                <td>
                                    <!-- 房时价 -->
                                    <ul class="ulBox longerInput">
                                        <li v-for="(items,p) in item.voucher" :key="p"><input type="text" v-model="items.weekend_time_price"></li>
                                    </ul>
                                </td>
                            </tr>
                        </tbody>
                    </table>




            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="editShow = false;">取 消</el-button>
                <el-button type="primary" @click="editYes(editForm.txt,editForm.combo_id,editForm)">确 定{{editForm.txt}}</el-button>
            </div>
        </el-dialog>
    </div>
</template>
<style lang="scss">
.storeInfo{
    .texta{
        textarea{resize:none !important}
    }
    .radioT_C{
     .el-radio__label{
            font-size: 12px
        }   
    }
    
}
.sortNumgood ol[data-v-0b7af70a]{z-index: 10;}
</style>
<style lang="scss" scoped>
.hoverBtn{display:block;text-align:center;margin-bottom:5px;cursor: pointer;transition: all 0.3s;}
.hoverBtn:hover{color:#F56C6C}
.thepriceTab{
    border:1px solid gray;
    border-right:0;
    width:560px;
    tr{
        border-bottom:1px solid gray;
        td{
            border-right: 1px solid gray;
            border-bottom:1px solid gray;
            text-align: center;
            vertical-align:middle;
            height: 30px; 
        }
    }
    thead{
        th{
            border-right:1px solid gray;
            border-bottom:1px solid gray;
            height: 30px;
            line-height: 30px;
        }
    }
    .ulBox{
        li{
            border-bottom:1px solid gray;
            height: 30px;
            line-height: 30px;
            input{
                width: 30px;
                height: 28px;
                border:none
            }
        }
        li:last-child{
            border-bottom:0;
            
        }
    }
    .longerInput{
        li{
            input{
                width:100%;
                text-align:center
            }
        }
    }
}

</style>
<script>
import { abc } from "../../../../js/abc.js";
import {potUrl} from '../../../../js/config_url.js';
import upload from '../../pop/upload.vue';
import ledBox from '../../pop/ledSynthetic.vue';
import sortgood from '../../pop/sortNumGood.vue'
var url= potUrl.comboIndex;
export default {
    components:{
        uploadBox:upload,
        sortgoodBox:sortgood,     
        ledBox:ledBox
    },
    data(){
        return {  
            categoryList:[],          
            tableData:[],
            total:0,
            size:20,
            pageNum:1,
            form: {},
            formEdit:{
                
            },
            editShow:false,
            editForm:{
            },
            editW:'120px',
            defunltImg:'this.src="'+require('../../img/error.png')+'"',
            limitList:[],
            weekend:[
                {val:'1',name:'周一'},
                {val:'2',name:'周二'},
                {val:'3',name:'周三'},
                {val:'4',name:'周四'},
                {val:'5',name:'周五'},
                {val:'6',name:'周六'},
                {val:'0',name:'周日'}
            ],
            platList:[
                {val:'1',name:'微信端'},                
                {val:'2',name:'安卓APP'},
                {val:'3',name:'iPhone端'},
                {val:'4',name:'PAD前台'},
            ],
            rommTimePriceTab:[
                {'day':'平日',roomList:[]},
                {'day':'周末',roomList:[]}
            ],
            roomList:[],//获取tab表数据
            charmber:[],//大中小包房的列表
            groupon:{},//获取对应包房档位的美团劵数
            period:[],//档位列表
            times_detail:[],
            tese_member_price:'',//特色优惠价
            tese_normal_price:'',//特色销售价
            computerSelected:'',//记录房时设置的val
            totalPrice:0,//所有商品的总价格
            led_images:[],//led组件传回来的数据
            autoLED:{},//自动合成LED传个子组件的参数
            use_days:[],//展示周次的显示
            use_plat:[],//展示客户端
            srcimg:[],//led-img图片展示
            inputpath:[],//led-input中的val
            show_combo_images:'',//套餐显示的图片链接src
            combo_images:'',//套餐封面的input-val
            cateId:'',//套餐类型-特色、超值
            meituanval:'',//控制开关 美团团购价格
            koubeival:'',//控制开关 口碑团购价格
            platarr:[],//平台属性
            roomCon:this.roomList,//为将roomList这个值赋予这个，而不更改roomList
        }
    },
    mounted(){
        var that = this;           
        that.geiCategory()//获取套餐分类
        abc.getList(that,url,that.form,changeList);
        abc.get(that,potUrl.comboGroupon,{},function(g) {
            that.groupon = g.data            
        })
        setTimeout(() => {
            that.roomList =  getPeriod(that)
        }, 1500);
         
    },
    watch:{
        cateId(newval,oldval){
            if(newval == '31'){
                //为特色套餐
                this.editForm.has_time = '1'
            }
        },
        'roomList'(nval){
            this.roomList = nval
            this.$forceUpdate()
            console.log('nval',nval)
        },
        'editForm.discount'(nval,oval){
            var that = this;
            that.computeComboPrice(that.computerSelected)
        }
    },
    created(){
        var that = this;
        setTimeout(() => {
            var str = $('.router-link-active').attr('href');
            abc.limit(that,str)// 权限  
        }, 500)            
    },
    computed:{
        count(){
            return this.$store.state.count
        },
    },
    methods:{
        platfn(val){
            var platval = val, that = this,mei=[],kou=[];
            $.each(platval,function(i,item){                
                if(item.indexOf('1-1') != -1 || item.indexOf('1-2') != -1){
                    that.meituanval = item;
                    mei.push(i)               
                }else{
                    that.meituanval = '';
                }
                if(mei.length == 2){
                   that.platarr.splice(mei[0],1) 
                }
                
                if(item.indexOf('2-1') !=-1 || item.indexOf('2-2') != -1){
                    that.koubeival = item 
                    kou.push(i)                   
                }else{
                    that.koubeival=''
                }
                if(kou.length == 2){
                   that.platarr.splice(kou[0],1) 
                }
            })
        },
        geiCategory(){
            var that = this;
            abc.get(that,potUrl.categoryList,{'cate_type': 2 },function(res){
                that.categoryList = res.data
            })
        },
        search(){
            var that = this;
            abc.getList(that,url,that.form,changeList);
        },
        theClick(a,b,c){
            let that = this;
            if(a == 'edit' || a == 'add' || a == 'copy'){    
                that.computerSelected = ''
                var store_combo_info = {},editobj={};
                if(a == 'edit' ||  a == 'copy'){
                            // 编辑
                    abc.get(that,potUrl.comboDetail,{combo_id:b},function(res){
                        editobj = res.data;
                        that.autoLED.combo_name = editobj.combo_name;                  
                        that.autoLED.goods_list = catetype(editobj.items_detail) ;  //autoLED这个参数是用来自动合成led

                        if(editobj.combo_images.length == 0){
                            editobj.combo_image = '';
                            editobj.show_combo_image = '';  
                        }else{
                            editobj.combo_image = editobj.combo_images[0];
                            editobj.show_combo_image = editobj.show_combo_images[0];
                        }
                        if(editobj.led_images.length <= 1){
                            
                        }
                        editobj.platform = editobj.platform.join(',');
                        // 这里的platform的值不固定，也许是一个，也许是两个或是三个
                        // 故给设置成ktv==魅ktv平台
                        // meituan==美团团购和美团预订
                        // koubei ==口碑团购和口碑预订
                        if(editobj.platform.indexOf('0') != -1){
                            editobj.ktv = '0'
                            that.platarr.push(editobj.ktv)
                        }
                        if(editobj.platform.indexOf('1') != -1){
                            editobj.meituan = "1-"+editobj.meituan_type
                            that.platarr.push(editobj.meituan)
                        }
                        if(editobj.platform.indexOf('2') != -1){
                            editobj.koubei = "2-"+editobj.koubei_type 
                            that.platarr.push(editobj.koubei)    
                        }
                        that.use_days = editobj.use_days
                        that.use_plat = editobj.use_plat
                        that.combo_images = editobj.combo_image
                        that.cateId = editobj.category_id
                        if(a == 'edit'){
                            editobj.txt = 'edit'//区分是编辑还是添加
                        }else{
                            editobj.txt = 'add'//区分是编辑还是添加
                        }
                        store_combo_info.a = editobj.show_combo_image
                        store_combo_info.b = editobj.led_images
                        store_combo_info.c = editobj.show_led_images
                        that.editForm = editobj
                        that.meituanval = editobj.meituan
                        that.koubeival = editobj.koubei   
                        
                        var totalp=0
                        $.each(editobj.items_detail,function (i,item) {
                            totalp+= parseInt(item.price)*parseInt(item.quantity) 
                        }) 
                        that.totalPrice = totalp                   
                        that.$store.commit('comboinfn',store_combo_info);
                    })
                }else{
                    
                    // 添加
                    // var editobj = {}
                    that.totalPrice = 0
                    editobj.category_id = '2';//套餐分类
                    editobj.has_time = '1';//是否含房时
                    editobj.combo_kind='';//适用场景-不含房时时有
                    editobj.combo_name = '';//套餐名称
                    editobj.show_combo_image = '';//套餐封面-src
                    editobj.combo_image = '';//套餐封面-input-val
                    editobj.ktv='';//魅ktv
                    editobj.meituan='';//美团显示的团购或预订
                    editobj.koubei='';//口碑显示的团购或预订
                    editobj.property = '';//有限期
                    editobj.date2 = '';//有效期至 的时间
                    editobj.date1 = '';//当天有效 的时间
                    editobj.items_detail = []; //商品及数量
                    editobj.led_images = ['',''];//LED封面：input-val
                    editobj.show_led_images = ['','']; //LED封面：src
                    editobj.use_days=["1", "2", "3", "4", "5", "6", "0"]//展示周次
                    editobj.use_plat = ["1", "2", "3", "4"];  //设置展示客户端
                    editobj.discount=''//商品系数
                    editobj.combo_desc=''//商品描述
                    editobj.combo_id = ''//没有编辑的套餐id
                    editobj.txt = 'add'//区分是编辑还是添加
                    // that.editForm = editForm
                    that.use_days = editobj.use_days
                    that.use_plat = editobj.use_plat
                    that.srcimg = editobj.led_images
                    that.inputpath = editobj.show_led_images
                    that.show_combo_images = editobj.show_combo_image
                    that.combo_images = editobj.combo_image
                    that.cateId = editobj.category_id
                    that.meituanval = editobj.meituan;
                    that.koubeival = editobj.koubei;
                    that.autoLED.combo_name = '';                  
                    that.autoLED.goods_list = {} ;
                    that.platarr=['0'];

                    store_combo_info.a = editobj.show_combo_image
                    store_combo_info.b = editobj.led_images
                    store_combo_info.c = editobj.show_led_images
                    that.editForm = editobj
                    that.$store.commit('comboinfn',store_combo_info);
                    
                }
            
                that.computeComboPrice('')
                that.editShow =true;
            }else if(a == 'shelf' || a == 'del'){

                var obj = {},urls='',txt='',type='';
                if(a == 'shelf'){
                    urls = 'operate/combo/shelve';
                    obj.combo_id = b;                    
                    if(c == 0){
                        txt = '是否要下架此商品？'
                        obj.status = 1;
                    }else{
                        txt = '是否要上架此商品？'
                        obj.status = 0;
                    }
                }else{
                    urls = 'operate/combo/delete';
                    obj.combo_id = b;
                    txt = '确定要删除此商品？';
                }
                abc.twoTips(that,urls,txt,obj,function() {
                    that.$message({
                        type: 'success',
                        message: '操作成功!'
                    });
                    abc.getList(that,url,that.form,changeList);
                })
            }
        },  
        editYes(txt,a,edit_data){
            // a是编辑是传入的combo_id
            // 编辑、添加时的确定按钮
            var that = this,obj={},tourl='';
            that.editForm = edit_data;

            if(txt=='add'){
                tourl = potUrl.comboadd
            }else{
                tourl = potUrl.comboedit;
                obj.combo_id = a
            }
            obj.platform = [];
            $.each(that.platarr,function(i,item){
                if(item.length == 1){
                    obj.platform.push(item)
                }
            })
            if(that.meituanval != ''){
                obj.platform.push(that.meituanval.split('-')[0])
                obj.meituan_type = that.meituanval.split('-')[1]
                if(obj.meituan_type == '1'){
                    if(editForm.meituan_unit_price != ''){
                        obj.meituan_unit_price = editForm.meituan_unit_price
                    }else{
                        that.$message({
                            type: 'success',
                            message: '美团团购的价格不能为空哟~'
                        })
                    }                   
                }
            }
            if(that.koubeival){
                obj.platform.push(that.koubeival.split('-')[0])
                obj.koubei_type = that.koubeival.split('-')[1]
                if(obj.koubei_type == '1'){
                    if(editForm.koubei_unit_price != ''){
                        obj.koubei_unit_price = editForm.koubei_unit_price
                    }else{
                        that.$message({
                            type: 'success',
                            message: '口碑团购的价格不能为空哟~'
                        })
                    }                   
                }
            }
            // platform(平台属性)、ues_days(展示周次)、use_plat(使用平台)这三个返回时是数组，但传给后台时是字符串
            obj.platform = obj.platform.join(',')//平台属性
            obj.category_id = that.cateId;//套餐分类
            obj.has_time =    that.editForm.has_time;//是否含房时
            obj.combo_kind =  that.editForm.combo_kind;//适用场景-不含房时时有
            obj.combo_name =  that.editForm.combo_name;//套餐名称
            var comboI = [];
            comboI.push(that.combo_images)
            obj.combo_images = JSON.stringify(comboI) ;//套餐封面-input-val
            obj.property =    that.editForm.property;//有限期
            obj.led_images =  JSON.stringify(that.editForm.led_images);//LED封面：input-val
            obj.use_days =    that.editForm.use_days.join(',') //展示周次
            obj.use_plat =    that.editForm.use_plat.join(',')  //设置展示客户端
            obj.discount =    that.editForm.discount//商品系数
            obj.combo_desc =  that.editForm.combo_desc//商品描述
            obj.item_infos =  JSON.stringify(that.editForm.items_detail)//套餐明细
            if(obj.has_time == '1'){
                var timeinfos = [];
                $.each(that.roomList,function(r,ritem) {                
                    $.each(ritem.voucher,function(v,vitem){
                        var vobj = {};
                        vobj.period_id = vitem.period_id
                        vobj.period_name = vitem.period_name
                        vobj.charmber_id = ritem.charmber_id
                        vobj.room_type = ritem.room_type
                        vobj.charmber_name = ritem.charmber_name
                        vobj.time_length = vitem.time_length
                        vobj.weekend_time_length = vitem.weekend_time_length
                        vobj.member_price = vitem.member_price
                        vobj.normal_price = vitem.normal_price
                        vobj.time_price = vitem.time_price
                        vobj.weekend_time_price = vitem.weekend_time_price
                        vobj.weekend_normal_price = vitem.weekend_normal_price
                        vobj.weekend_member_price = vitem.weekend_member_price
                        vobj.type = 1
                        timeinfos.push(vobj)
                    })
                })
                obj.time_infos = JSON.stringify(timeinfos)//房时设置明细    
            }else{
                comboKind = that.editForm.combo_kind
                var item = {},itemobj=[];
                item.period_id = 0;
                item.period_name = '';
                item.charmber_id = 0;
                item.charmber_name = '';
                item.time_length = 0;
                item.weekend_time_length = 0;
                item.time_price = 0;
                item.weekend_time_price = 0;
                item.type = 2;

                item.member_price = item.weekend_member_price = that.tese_member_price
                item.normal_price = item.weekend_normal_price = that.tese_normal_price
                itemobj.push(item)
                obj.time_infos = JSON.stringify(itemobj)
            }
            
            abc.post(that,tourl,obj,function(res){
                abc.getList(that,url,that.form,changeList);
                that.editShow =false;
            })

        },
        imgUrl(data){
            // 上传套餐图片
            this.combo_images = data;
        },
        getsearchgoods(getGoodList){
            // 通过子组件得到需要添加的商品数组；
            var that = this;
            that.editForm.items_detail = getGoodList;
            
             console.log('ggo')
            var str = '',price=0;
            $.each(getGoodList,function(i,items) {
                str += items.item_name+items.spec+items.quantity+items.unit+'\n';
                price += parseFloat(items.unit_price*items.quantity)
            })
            that.editForm.combo_desc = str;//套餐描述
            that.totalPrice = price;//商品总价格
            that.autoLED.goods_list = catetype(getGoodList)//自动生成LED图的其中参数
            that.$forceUpdate();
            that.computeComboPrice(that.computerSelected) 
        },
        useDays(value) {
            // 复选框变化
            // console.log('useDays',value)
        },
        usePlat(value) {
            // 复选框变化
            // console.log('usePlat',value)
        },
        changePage(val){
            var that = this;
            that.pageNum = val;
            this.form.page = val;
           abc.getList(that,url,that.form,changeList);
        },
        computeComboPrice(n=''){
            // 根据条件生成相对应的房时
            var that = this;
            changeroom(that,n)           
        },
        led_data_img(data){
            // 获取led_images数组的数据 ---从ledBox的组件里得到
            let that = this;
            that.led_images = data;
        }


    }
}
// 将商品详情的里的cate_name修改成type
function catetype(arr) {
    $.each(arr,function(i,item){
        arr[i].type = item.cate_name
    })
    return arr
}
function  changeList(data) {
    $.each(data,function(i,item){
        // 是否含房时
        if(item.has_time == 1){
            item.has_time_cn = '是'
        }else if(item.has_time == 0){
            item.has_time_cn = '否'
        }else{
            item.has_time_cn='/'
        }
        // 平台属性显示
        item.platform_cn = ''
        if(item.platform.indexOf('0') != -1){
            item.platform_cn += '魅KTV<br />'
        }  
        if (item.meituan_type == 1) { //团购
            item.platform_cn += '美团团购<br />';
        } else if (item.meituan_type == 2) {
            item.platform_cn += '美团预订<br />';
        }

        if (item.koubei_type == 2) {
            item.platform_cn += '口碑预订<br />';
        } else if (item.koubei_type == 1) {
            item.platform_cn += '口碑团购';
        } 
        // 套餐明细
        item.combo_desc_cn=''
        var comboArray = item.combo_desc.split('+');
        for(var i = 0; i < comboArray.length; i++) {
            item.combo_desc_cn += '<p>' + comboArray[i] + '</p>'
        }
        // 套餐级别
        if(item.combo_cate == '1'){
            item.combo_cate_cn = 'L1';
        }else if(item.combo_cate == '2'){
            item.combo_cate_cn = 'L2';
        }else{
            item.combo_cate_cn = 'L3';
        }
        
    })
}
function getPeriod(that) { 
    // charmber:[],//大中小包房的列表
    // groupon:{},//获取对应包房档位的美团劵数
    // period:[],//档位列表
    var rooml = that.groupon.groupon_conf;
    for(var i=0;i<that.groupon.groupon_conf.length;i++){
        // that.groupon.groupon_conf[i].room_type = that.charmber[i].room_type;
        for(var a=0;a<that.groupon.groupon_conf[i].voucher.length;a++){
            var dwlist = that.groupon.groupon_conf[i].voucher[a];

            dwlist.member_price = dwlist.weekend_member_price = ''           
            dwlist.normal_price =dwlist.weekend_normal_price = ''
            dwlist.time_price = dwlist.weekend_time_price = '' ;
            dwlist.time_length = dwlist.weekend_time_length = '' 
        }
    }
        // 第一层 区分是平日还是周末
    return  that.groupon.groupon_conf;
}
function  changeroom(that,n) {
    for(var j=0;j<that.groupon.groupon_conf.length;j++){
        // 小中大包房类型；   
            var roomlist = that.groupon.groupon_conf[j]      
        for(var o=0;o<roomlist.voucher.length;o++){
            // 阳光、黄金档等档位；
            var dwlist = roomlist.voucher[o];
            editLen(that,roomlist,dwlist,n) 
        }
       
    }
    that.roomList = that.groupon.groupon_conf;
    that.$forceUpdate()
}
function editLen(that,roomlist,dwlist,n) {
    // console.log('room',roomlist)
    if(n == ''){
        dwlist.member_price = dwlist.weekend_member_price ='' ;         
        dwlist.normal_price =dwlist.weekend_normal_price = '';
        dwlist.time_price = dwlist.weekend_time_price = '' ; 
        dwlist.time_length = dwlist.weekend_time_length = ''            
    }else{
        if(n == 1 || n==2 || n == 3){
            dwlist.member_price = dwlist.weekend_member_price =that.tese_member_price           
            dwlist.normal_price =dwlist.weekend_normal_price = that.tese_normal_price
            dwlist.time_price = dwlist.weekend_time_price = '' ;
        }else{
            // 优惠价
            dwlist.member_price = abc.ModifyPrice(dwlist.groupon_num*that.groupon.groupon_price + that.totalPrice*that.editForm.discount) 
            dwlist.weekend_member_price = abc.ModifyPrice(dwlist.weekend_groupon_num*that.groupon.groupon_price + that.totalPrice*that.editForm.discount)  
            // 销售价
            dwlist.normal_price =  Math.floor(dwlist.groupon_num*that.groupon.groupon_price + that.totalPrice)    
            dwlist.weekend_normal_price = Math.floor(dwlist.weekend_groupon_num*that.groupon.groupon_price + that.totalPrice)
            // 房时价
            dwlist.time_price = Math.floor(dwlist.groupon_num*that.groupon.groupon_price)
            dwlist.weekend_time_price = Math.floor(dwlist.weekend_groupon_num*that.groupon.groupon_price) ;
        }
    }
    switch (n) {
        case 1:
            // 小、中包房中的阳光：6；黄金：3；午夜周内7；午夜周末：6；
            if(roomlist.room_type > 2){
                if(dwlist.period_id == '1'){
                    // 阳光档
                    dwlist.time_length = '6'
                    dwlist.weekend_time_length = '6'
                }else if(dwlist.period_id == '2'){
                    // 黄金档
                    dwlist.time_length = '3'
                    dwlist.weekend_time_length = '3'
                }else if(dwlist.period_id == '3'){
                    // 午夜档
                    dwlist.time_length = '7'
                    dwlist.weekend_time_length = '6'                                        
                }                                                    
            }else{
                dwlist.time_length = dwlist.weekend_time_length = that.groupon.store_duration  
            }
            
            break; 
        case 2:
            // 全部全天欢唱；
            dwlist.time_length = dwlist.weekend_time_length = that.groupon.store_duration 
            break;
        case 3:
            // 全部档位3小时；
            dwlist.time_length = dwlist.weekend_time_length = '3' 
            break; 
        case 4:
            // 仅阳光档能用，周末周内3小时；
            if(dwlist.period_name == '阳光档'){
                // 阳光档
                dwlist.time_length = dwlist.weekend_time_length = '3';
            }else{
                // 其他档位
                dwlist.time_length = dwlist.weekend_time_length = '';//时长
                dwlist.member_price = dwlist.weekend_member_price = ''          
                dwlist.normal_price =dwlist.weekend_normal_price = ''
                dwlist.time_price = dwlist.weekend_time_price = '' ;
            }            
            break; 
        case 5:
            // 仅阳光档能用，周末周内3小时；
            if(dwlist.period_name == '阳光档'){
                // 阳光档
                dwlist.time_length = '4'
                dwlist.weekend_time_length = '3';
            }else{
                // 其他档位
                dwlist.time_length = dwlist.weekend_time_length = '';//时长
                dwlist.member_price = dwlist.weekend_member_price = ''          
                dwlist.normal_price =dwlist.weekend_normal_price = ''
                dwlist.time_price = dwlist.weekend_time_price = '' ;
            }            
            break;
        case 6:
            // 仅阳光档能用，周末周内3小时；
            if(dwlist.period_name == '阳光档'){
                // 阳光档
                dwlist.time_length = dwlist.weekend_time_length = '6'
            }else if(dwlist.period_name == '黄金档'){
                // 黄金
                dwlist.time_length = dwlist.weekend_time_length = '3';//时长
            }else if(dwlist.period_name == '午夜档'){
               //午夜
               dwlist.time_length = '7'
               dwlist.weekend_time_length = '6'; 
            }         
            break;
        case 7:
            // 仅阳光档能用，周末周内3小时；
            if(dwlist.period_name == '阳光档'){
                // 阳光档
                dwlist.time_length = dwlist.weekend_time_length = '6'
            }else if(dwlist.period_name == '黄金档'){
                // 黄金
                dwlist.time_length = '4'
                dwlist.weekend_time_length = '3';
            }else if(dwlist.period_name == '午夜档'){
               //午夜
               dwlist.time_length = '7'
               dwlist.weekend_time_length = '6'; 
            }         
            break;
        case 8:
            // 仅阳光档能用，周末周内3小时；
            dwlist.time_length = dwlist.weekend_time_length = '3';//时长       
            break;
        default:
            break;
    }
}
// function changeroomlist(that,obj){
//     // 将详情中的time_infos变换为roomlist的格式
//     var objarr = [],objo={};
//     $.each(obj,function(o,oitem){
//         var roomtype = oitem.room_type;
//         var charmber_name = oitem.charmber_name
//         if(objo.room_type != roomtype || objo.charmber_name != charmber_name){
//             objo={}
//             objo.charmber_id = oitem.charmber_id;
//             objo.charmber_name = oitem.charmber_name;
//             objo.room_type = oitem.room_type;
//             objo.voucher=[] 
//              var objv = {};
//             objv.groupon_duration = oitem.groupon_duration
//             objv.groupon_num = oitem.groupon_num
//             objv.weekend_groupon_num = oitem.groupon_duration
//             objv.period_id = oitem.period_id
//             objv.period_name = oitem.period_name
//             objv.weekend_member_price = oitem.weekend_member_price
//             objv.member_price = oitem.member_price
//             objv.weekend_normal_price = oitem.weekend_normal_price
//             objv.normal_price = oitem.normal_price
//             objv.weekend_time_price = oitem.weekend_time_price
//             objv.time_price = oitem.time_price
//             objv.weekend_time_length = oitem.weekend_time_length
//             objv.time_length = oitem.time_length;
//             objo.voucher.push(objv)
//             objarr.push(objo)  
//         }else{
//             var objv = {};
//             objv.groupon_duration = oitem.groupon_duration
//             objv.groupon_num = oitem.groupon_num
//             objv.weekend_groupon_num = oitem.groupon_duration
//             objv.period_id = oitem.period_id
//             objv.period_name = oitem.period_name
//             objv.weekend_member_price = oitem.weekend_member_price
//             objv.member_price = oitem.member_price
//             objv.weekend_normal_price = oitem.weekend_normal_price
//             objv.normal_price = oitem.normal_price
//             objv.weekend_time_price = oitem.weekend_time_price
//             objv.time_price = oitem.time_price
//             objv.weekend_time_length = oitem.weekend_time_length
//             objv.time_length = oitem.time_length;
//             objo.voucher.push(objv)
//         }
//     })   
//     return objarr
// }
</script>